package com.msb.tank;

import com.msb.tank.constant.Dir;
import com.msb.tank.constant.Group;

/**
 * @Description :
 * @Author : guxuemin
 * @Version : V1.0.0
 * @Date : 2022/9/21 22:03
 */
public class Main {
    public static void main(String[] args) {
        TankFrame tf = TankFrame.INSTANCE;
        tf.setVisible(true);
        final int tankInitCount = Integer.parseInt(String.valueOf(PropertyMgr.get("tankInitCount")));
        for (int i = 0; i < tankInitCount; i++) {
            tf.addTank(new Tank(50 + i * 80, 200, Dir.DOWN, Group.BAD, tf));
        }
        //music
        new Thread(() -> new Audio("audio/war1.wav").loop()).start();
        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(25);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                tf.repaint();
            }
        }).start();

        new Thread(() -> {
            while (true) {
                tf.tanks.forEach((id, tank) -> {
                    tank.setMoving(true);
                    if (tank.isBound()) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        tank.setDir(Dir.DOWN);
                    }
                    if (tank.isBound()) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println(tank.getId());
                        tank.setDir(Dir.UP);
                    }
                });
            }
        }).start();

    }
}
